<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>treecontrol.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_tree_treecontrol.js.html">treecontrol.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2007 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Definition of the goog.ui.tree.TreeControl class, which
<a name="line17"></a> * provides a way to view a hierarchical set of data.
<a name="line18"></a> *
<a name="line19"></a> * @author arv@google.com (Erik Arvidsson)
<a name="line20"></a> * @author eae@google.com (Emil A Eklund)
<a name="line21"></a> * @author jonp@google.com (Jon Perlow)
<a name="line22"></a> * @author annams@google.com (Srinivas Annam)
<a name="line23"></a> *
<a name="line24"></a> * This is a based on the webfx tree control. It since been updated to add
<a name="line25"></a> * typeahead support, as well as accessibility support using ARIA framework.
<a name="line26"></a> *
<a name="line27"></a> * @see ../../demos/tree/demo.html
<a name="line28"></a> */
<a name="line29"></a>
<a name="line30"></a>goog.provide(&#39;goog.ui.tree.TreeControl&#39;);
<a name="line31"></a>
<a name="line32"></a>goog.require(&#39;goog.a11y.aria&#39;);
<a name="line33"></a>goog.require(&#39;goog.asserts&#39;);
<a name="line34"></a>goog.require(&#39;goog.debug.Logger&#39;);
<a name="line35"></a>goog.require(&#39;goog.dom.classes&#39;);
<a name="line36"></a>goog.require(&#39;goog.events.EventType&#39;);
<a name="line37"></a>goog.require(&#39;goog.events.FocusHandler&#39;);
<a name="line38"></a>goog.require(&#39;goog.events.KeyHandler&#39;);
<a name="line39"></a>goog.require(&#39;goog.events.KeyHandler.EventType&#39;);
<a name="line40"></a>goog.require(&#39;goog.ui.tree.BaseNode&#39;);
<a name="line41"></a>goog.require(&#39;goog.ui.tree.TreeNode&#39;);
<a name="line42"></a>goog.require(&#39;goog.ui.tree.TypeAhead&#39;);
<a name="line43"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line44"></a>
<a name="line45"></a>
<a name="line46"></a>
<a name="line47"></a>/**
<a name="line48"></a> * This creates a TreeControl object. A tree control provides a way to
<a name="line49"></a> * view a hierarchical set of data.
<a name="line50"></a> * @param {string} html The HTML content of the node label.
<a name="line51"></a> * @param {Object=} opt_config The configuration for the tree. See
<a name="line52"></a> *    goog.ui.tree.TreeControl.defaultConfig. If not specified, a default config
<a name="line53"></a> *    will be used.
<a name="line54"></a> * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper.
<a name="line55"></a> * @constructor
<a name="line56"></a> * @extends {goog.ui.tree.BaseNode}
<a name="line57"></a> */
<a name="line58"></a>goog.ui.tree.TreeControl = function(html, opt_config, opt_domHelper) {
<a name="line59"></a>  goog.ui.tree.BaseNode.call(this, html, opt_config, opt_domHelper);
<a name="line60"></a>
<a name="line61"></a>  // The root is open and selected by default.
<a name="line62"></a>  this.setExpandedInternal(true);
<a name="line63"></a>  this.setSelectedInternal(true);
<a name="line64"></a>
<a name="line65"></a>  this.selectedItem_ = this;
<a name="line66"></a>
<a name="line67"></a>  /**
<a name="line68"></a>   * Used for typeahead support.
<a name="line69"></a>   * @type {!goog.ui.tree.TypeAhead}
<a name="line70"></a>   * @private
<a name="line71"></a>   */
<a name="line72"></a>  this.typeAhead_ = new goog.ui.tree.TypeAhead();
<a name="line73"></a>
<a name="line74"></a>  if (goog.userAgent.IE) {
<a name="line75"></a>    /** @preserveTry */
<a name="line76"></a>    try {
<a name="line77"></a>      // works since IE6SP1
<a name="line78"></a>      document.execCommand(&#39;BackgroundImageCache&#39;, false, true);
<a name="line79"></a>    } catch (e) {
<a name="line80"></a>      this.logger_.warning(&#39;Failed to enable background image cache&#39;);
<a name="line81"></a>    }
<a name="line82"></a>  }
<a name="line83"></a>};
<a name="line84"></a>goog.inherits(goog.ui.tree.TreeControl, goog.ui.tree.BaseNode);
<a name="line85"></a>
<a name="line86"></a>
<a name="line87"></a>/**
<a name="line88"></a> * The object handling keyboard events.
<a name="line89"></a> * @type {goog.events.KeyHandler}
<a name="line90"></a> * @private
<a name="line91"></a> */
<a name="line92"></a>goog.ui.tree.TreeControl.prototype.keyHandler_ = null;
<a name="line93"></a>
<a name="line94"></a>
<a name="line95"></a>/**
<a name="line96"></a> * The object handling focus events.
<a name="line97"></a> * @type {goog.events.FocusHandler}
<a name="line98"></a> * @private
<a name="line99"></a> */
<a name="line100"></a>goog.ui.tree.TreeControl.prototype.focusHandler_ = null;
<a name="line101"></a>
<a name="line102"></a>
<a name="line103"></a>/**
<a name="line104"></a> * Logger
<a name="line105"></a> * @type {goog.debug.Logger}
<a name="line106"></a> * @private
<a name="line107"></a> */
<a name="line108"></a>goog.ui.tree.TreeControl.prototype.logger_ =
<a name="line109"></a>    goog.debug.Logger.getLogger(&#39;goog.ui.tree.TreeControl&#39;);
<a name="line110"></a>
<a name="line111"></a>
<a name="line112"></a>/**
<a name="line113"></a> * Whether the tree is focused.
<a name="line114"></a> * @type {boolean}
<a name="line115"></a> * @private
<a name="line116"></a> */
<a name="line117"></a>goog.ui.tree.TreeControl.prototype.focused_ = false;
<a name="line118"></a>
<a name="line119"></a>
<a name="line120"></a>/**
<a name="line121"></a> * Child node that currently has focus.
<a name="line122"></a> * @type {goog.ui.tree.BaseNode}
<a name="line123"></a> * @private
<a name="line124"></a> */
<a name="line125"></a>goog.ui.tree.TreeControl.prototype.focusedNode_ = null;
<a name="line126"></a>
<a name="line127"></a>
<a name="line128"></a>/**
<a name="line129"></a> * Whether to show lines.
<a name="line130"></a> * @type {boolean}
<a name="line131"></a> * @private
<a name="line132"></a> */
<a name="line133"></a>goog.ui.tree.TreeControl.prototype.showLines_ = true;
<a name="line134"></a>
<a name="line135"></a>
<a name="line136"></a>/**
<a name="line137"></a> * Whether to show expanded lines.
<a name="line138"></a> * @type {boolean}
<a name="line139"></a> * @private
<a name="line140"></a> */
<a name="line141"></a>goog.ui.tree.TreeControl.prototype.showExpandIcons_ = true;
<a name="line142"></a>
<a name="line143"></a>
<a name="line144"></a>/**
<a name="line145"></a> * Whether to show the root node.
<a name="line146"></a> * @type {boolean}
<a name="line147"></a> * @private
<a name="line148"></a> */
<a name="line149"></a>goog.ui.tree.TreeControl.prototype.showRootNode_ = true;
<a name="line150"></a>
<a name="line151"></a>
<a name="line152"></a>/**
<a name="line153"></a> * Whether to show the root lines.
<a name="line154"></a> * @type {boolean}
<a name="line155"></a> * @private
<a name="line156"></a> */
<a name="line157"></a>goog.ui.tree.TreeControl.prototype.showRootLines_ = true;
<a name="line158"></a>
<a name="line159"></a>
<a name="line160"></a>/** @override */
<a name="line161"></a>goog.ui.tree.TreeControl.prototype.getTree = function() {
<a name="line162"></a>  return this;
<a name="line163"></a>};
<a name="line164"></a>
<a name="line165"></a>
<a name="line166"></a>/** @override */
<a name="line167"></a>goog.ui.tree.TreeControl.prototype.getDepth = function() {
<a name="line168"></a>  return 0;
<a name="line169"></a>};
<a name="line170"></a>
<a name="line171"></a>
<a name="line172"></a>/**
<a name="line173"></a> * Expands the parent chain of this node so that it is visible.
<a name="line174"></a> * @override
<a name="line175"></a> */
<a name="line176"></a>goog.ui.tree.TreeControl.prototype.reveal = function() {
<a name="line177"></a>  // always expanded by default
<a name="line178"></a>  // needs to be overriden so that we don&#39;t try to reveal our parent
<a name="line179"></a>  // which is a generic component
<a name="line180"></a>};
<a name="line181"></a>
<a name="line182"></a>
<a name="line183"></a>/**
<a name="line184"></a> * Handles focus on the tree.
<a name="line185"></a> * @param {!goog.events.BrowserEvent} e The browser event.
<a name="line186"></a> * @private
<a name="line187"></a> */
<a name="line188"></a>goog.ui.tree.TreeControl.prototype.handleFocus_ = function(e) {
<a name="line189"></a>  this.focused_ = true;
<a name="line190"></a>  goog.dom.classes.add(this.getElement(), &#39;focused&#39;);
<a name="line191"></a>
<a name="line192"></a>  if (this.selectedItem_) {
<a name="line193"></a>    this.selectedItem_.select();
<a name="line194"></a>  }
<a name="line195"></a>};
<a name="line196"></a>
<a name="line197"></a>
<a name="line198"></a>/**
<a name="line199"></a> * Handles blur on the tree.
<a name="line200"></a> * @param {!goog.events.BrowserEvent} e The browser event.
<a name="line201"></a> * @private
<a name="line202"></a> */
<a name="line203"></a>goog.ui.tree.TreeControl.prototype.handleBlur_ = function(e) {
<a name="line204"></a>  this.focused_ = false;
<a name="line205"></a>  goog.dom.classes.remove(this.getElement(), &#39;focused&#39;);
<a name="line206"></a>};
<a name="line207"></a>
<a name="line208"></a>
<a name="line209"></a>/**
<a name="line210"></a> * @return {boolean} Whether the tree has keyboard focus.
<a name="line211"></a> */
<a name="line212"></a>goog.ui.tree.TreeControl.prototype.hasFocus = function() {
<a name="line213"></a>  return this.focused_;
<a name="line214"></a>};
<a name="line215"></a>
<a name="line216"></a>
<a name="line217"></a>/** @override */
<a name="line218"></a>goog.ui.tree.TreeControl.prototype.getExpanded = function() {
<a name="line219"></a>  return !this.showRootNode_ ||
<a name="line220"></a>      goog.ui.tree.TreeControl.superClass_.getExpanded.call(this);
<a name="line221"></a>};
<a name="line222"></a>
<a name="line223"></a>
<a name="line224"></a>/** @override */
<a name="line225"></a>goog.ui.tree.TreeControl.prototype.setExpanded = function(expanded) {
<a name="line226"></a>  if (!this.showRootNode_) {
<a name="line227"></a>    this.setExpandedInternal(expanded);
<a name="line228"></a>  } else {
<a name="line229"></a>    goog.ui.tree.TreeControl.superClass_.setExpanded.call(this, expanded);
<a name="line230"></a>  }
<a name="line231"></a>};
<a name="line232"></a>
<a name="line233"></a>
<a name="line234"></a>/** @override */
<a name="line235"></a>goog.ui.tree.TreeControl.prototype.getExpandIconHtml = function() {
<a name="line236"></a>  // no expand icon for root element
<a name="line237"></a>  return &#39;&#39;;
<a name="line238"></a>};
<a name="line239"></a>
<a name="line240"></a>
<a name="line241"></a>/** @override */
<a name="line242"></a>goog.ui.tree.TreeControl.prototype.getIconElement = function() {
<a name="line243"></a>  var el = this.getRowElement();
<a name="line244"></a>  return el ? /** @type {Element} */ (el.firstChild) : null;
<a name="line245"></a>};
<a name="line246"></a>
<a name="line247"></a>
<a name="line248"></a>/** @override */
<a name="line249"></a>goog.ui.tree.TreeControl.prototype.getExpandIconElement = function() {
<a name="line250"></a>  // no expand icon for root element
<a name="line251"></a>  return null;
<a name="line252"></a>};
<a name="line253"></a>
<a name="line254"></a>
<a name="line255"></a>/** @override */
<a name="line256"></a>goog.ui.tree.TreeControl.prototype.updateExpandIcon = function() {
<a name="line257"></a>  // no expand icon
<a name="line258"></a>};
<a name="line259"></a>
<a name="line260"></a>
<a name="line261"></a>/** @override */
<a name="line262"></a>goog.ui.tree.TreeControl.prototype.getRowClassName = function() {
<a name="line263"></a>  return goog.ui.tree.TreeControl.superClass_.getRowClassName.call(this) +
<a name="line264"></a>      (this.showRootNode_ ? &#39;&#39; : &#39; &#39; + this.getConfig().cssHideRoot);
<a name="line265"></a>};
<a name="line266"></a>
<a name="line267"></a>
<a name="line268"></a>/**
<a name="line269"></a> * Returns the source for the icon.
<a name="line270"></a> * @return {string} Src for the icon.
<a name="line271"></a> * @override
<a name="line272"></a> */
<a name="line273"></a>goog.ui.tree.TreeControl.prototype.getCalculatedIconClass = function() {
<a name="line274"></a>  var expanded = this.getExpanded();
<a name="line275"></a>  if (expanded &amp;&amp; this.expandedIconClass_) {
<a name="line276"></a>    return this.expandedIconClass_;
<a name="line277"></a>  }
<a name="line278"></a>  if (!expanded &amp;&amp; this.iconClass_) {
<a name="line279"></a>    return this.iconClass_;
<a name="line280"></a>  }
<a name="line281"></a>
<a name="line282"></a>  // fall back on default icons
<a name="line283"></a>  var config = this.getConfig();
<a name="line284"></a>  if (expanded &amp;&amp; config.cssExpandedRootIcon) {
<a name="line285"></a>    return config.cssTreeIcon + &#39; &#39; + config.cssExpandedRootIcon;
<a name="line286"></a>  } else if (!expanded &amp;&amp; config.cssCollapsedRootIcon) {
<a name="line287"></a>    return config.cssTreeIcon + &#39; &#39; + config.cssCollapsedRootIcon;
<a name="line288"></a>  }
<a name="line289"></a>  return &#39;&#39;;
<a name="line290"></a>};
<a name="line291"></a>
<a name="line292"></a>
<a name="line293"></a>/**
<a name="line294"></a> * Sets the selected item.
<a name="line295"></a> * @param {goog.ui.tree.BaseNode} node The item to select.
<a name="line296"></a> */
<a name="line297"></a>goog.ui.tree.TreeControl.prototype.setSelectedItem = function(node) {
<a name="line298"></a>  if (this.selectedItem_ == node) {
<a name="line299"></a>    return;
<a name="line300"></a>  }
<a name="line301"></a>
<a name="line302"></a>  var hadFocus = false;
<a name="line303"></a>  if (this.selectedItem_) {
<a name="line304"></a>    hadFocus = this.selectedItem_ == this.focusedNode_;
<a name="line305"></a>    this.selectedItem_.setSelectedInternal(false);
<a name="line306"></a>  }
<a name="line307"></a>
<a name="line308"></a>  this.selectedItem_ = node;
<a name="line309"></a>
<a name="line310"></a>  if (node) {
<a name="line311"></a>    node.setSelectedInternal(true);
<a name="line312"></a>    if (hadFocus) {
<a name="line313"></a>      node.select();
<a name="line314"></a>    }
<a name="line315"></a>  }
<a name="line316"></a>
<a name="line317"></a>  this.dispatchEvent(goog.events.EventType.CHANGE);
<a name="line318"></a>};
<a name="line319"></a>
<a name="line320"></a>
<a name="line321"></a>/**
<a name="line322"></a> * Returns the selected item.
<a name="line323"></a> * @return {goog.ui.tree.BaseNode} The currently selected item.
<a name="line324"></a> */
<a name="line325"></a>goog.ui.tree.TreeControl.prototype.getSelectedItem = function() {
<a name="line326"></a>  return this.selectedItem_;
<a name="line327"></a>};
<a name="line328"></a>
<a name="line329"></a>
<a name="line330"></a>/**
<a name="line331"></a> * Sets whether to show lines.
<a name="line332"></a> * @param {boolean} b Whether to show lines.
<a name="line333"></a> */
<a name="line334"></a>goog.ui.tree.TreeControl.prototype.setShowLines = function(b) {
<a name="line335"></a>  if (this.showLines_ != b) {
<a name="line336"></a>    this.showLines_ = b;
<a name="line337"></a>    if (this.isInDocument()) {
<a name="line338"></a>      this.updateLinesAndExpandIcons_();
<a name="line339"></a>    }
<a name="line340"></a>  }
<a name="line341"></a>};
<a name="line342"></a>
<a name="line343"></a>
<a name="line344"></a>/**
<a name="line345"></a> * @return {boolean} Whether to show lines.
<a name="line346"></a> */
<a name="line347"></a>goog.ui.tree.TreeControl.prototype.getShowLines = function() {
<a name="line348"></a>  return this.showLines_;
<a name="line349"></a>};
<a name="line350"></a>
<a name="line351"></a>
<a name="line352"></a>/**
<a name="line353"></a> * Updates the lines after the tree has been drawn.
<a name="line354"></a> * @private
<a name="line355"></a> */
<a name="line356"></a>goog.ui.tree.TreeControl.prototype.updateLinesAndExpandIcons_ = function() {
<a name="line357"></a>  var tree = this;
<a name="line358"></a>  var showLines = tree.getShowLines();
<a name="line359"></a>  var showRootLines = tree.getShowRootLines();
<a name="line360"></a>  // Recursively walk through all nodes and update the class names of the
<a name="line361"></a>  // expand icon and the children element.
<a name="line362"></a>  function updateShowLines(node) {
<a name="line363"></a>    var childrenEl = node.getChildrenElement();
<a name="line364"></a>    if (childrenEl) {
<a name="line365"></a>      var hideLines = !showLines || tree == node.getParent() &amp;&amp; !showRootLines;
<a name="line366"></a>      var childClass = hideLines ? node.getConfig().cssChildrenNoLines :
<a name="line367"></a>          node.getConfig().cssChildren;
<a name="line368"></a>      childrenEl.className = childClass;
<a name="line369"></a>
<a name="line370"></a>      var expandIconEl = node.getExpandIconElement();
<a name="line371"></a>      if (expandIconEl) {
<a name="line372"></a>        expandIconEl.className = node.getExpandIconClass();
<a name="line373"></a>      }
<a name="line374"></a>    }
<a name="line375"></a>    node.forEachChild(updateShowLines);
<a name="line376"></a>  }
<a name="line377"></a>  updateShowLines(this);
<a name="line378"></a>};
<a name="line379"></a>
<a name="line380"></a>
<a name="line381"></a>/**
<a name="line382"></a> * Sets whether to show root lines.
<a name="line383"></a> * @param {boolean} b Whether to show root lines.
<a name="line384"></a> */
<a name="line385"></a>goog.ui.tree.TreeControl.prototype.setShowRootLines = function(b) {
<a name="line386"></a>  if (this.showRootLines_ != b) {
<a name="line387"></a>    this.showRootLines_ = b;
<a name="line388"></a>    if (this.isInDocument()) {
<a name="line389"></a>      this.updateLinesAndExpandIcons_();
<a name="line390"></a>    }
<a name="line391"></a>  }
<a name="line392"></a>};
<a name="line393"></a>
<a name="line394"></a>
<a name="line395"></a>/**
<a name="line396"></a> * @return {boolean} Whether to show root lines.
<a name="line397"></a> */
<a name="line398"></a>goog.ui.tree.TreeControl.prototype.getShowRootLines = function() {
<a name="line399"></a>  return this.showRootLines_;
<a name="line400"></a>};
<a name="line401"></a>
<a name="line402"></a>
<a name="line403"></a>/**
<a name="line404"></a> * Sets whether to show expand icons.
<a name="line405"></a> * @param {boolean} b Whether to show expand icons.
<a name="line406"></a> */
<a name="line407"></a>goog.ui.tree.TreeControl.prototype.setShowExpandIcons = function(b) {
<a name="line408"></a>  if (this.showExpandIcons_ != b) {
<a name="line409"></a>    this.showExpandIcons_ = b;
<a name="line410"></a>    if (this.isInDocument()) {
<a name="line411"></a>      this.updateLinesAndExpandIcons_();
<a name="line412"></a>    }
<a name="line413"></a>  }
<a name="line414"></a>};
<a name="line415"></a>
<a name="line416"></a>
<a name="line417"></a>/**
<a name="line418"></a> * @return {boolean} Whether to show expand icons.
<a name="line419"></a> */
<a name="line420"></a>goog.ui.tree.TreeControl.prototype.getShowExpandIcons = function() {
<a name="line421"></a>  return this.showExpandIcons_;
<a name="line422"></a>};
<a name="line423"></a>
<a name="line424"></a>
<a name="line425"></a>/**
<a name="line426"></a> * Sets whether to show the root node.
<a name="line427"></a> * @param {boolean} b Whether to show the root node.
<a name="line428"></a> */
<a name="line429"></a>goog.ui.tree.TreeControl.prototype.setShowRootNode = function(b) {
<a name="line430"></a>  if (this.showRootNode_ != b) {
<a name="line431"></a>    this.showRootNode_ = b;
<a name="line432"></a>    if (this.isInDocument()) {
<a name="line433"></a>      var el = this.getRowElement();
<a name="line434"></a>      if (el) {
<a name="line435"></a>        el.className = this.getRowClassName();
<a name="line436"></a>      }
<a name="line437"></a>    }
<a name="line438"></a>    // Ensure that we do not hide the selected item.
<a name="line439"></a>    if (!b &amp;&amp; this.getSelectedItem() == this &amp;&amp; this.getFirstChild()) {
<a name="line440"></a>      this.setSelectedItem(this.getFirstChild());
<a name="line441"></a>    }
<a name="line442"></a>  }
<a name="line443"></a>};
<a name="line444"></a>
<a name="line445"></a>
<a name="line446"></a>/**
<a name="line447"></a> * @return {boolean} Whether to show the root node.
<a name="line448"></a> */
<a name="line449"></a>goog.ui.tree.TreeControl.prototype.getShowRootNode = function() {
<a name="line450"></a>  return this.showRootNode_;
<a name="line451"></a>};
<a name="line452"></a>
<a name="line453"></a>
<a name="line454"></a>/**
<a name="line455"></a> * Add roles and states.
<a name="line456"></a> * @protected
<a name="line457"></a> * @override
<a name="line458"></a> */
<a name="line459"></a>goog.ui.tree.TreeControl.prototype.initAccessibility = function() {
<a name="line460"></a>  goog.ui.tree.TreeControl.superClass_.initAccessibility.call(this);
<a name="line461"></a>
<a name="line462"></a>  var elt = this.getElement();
<a name="line463"></a>  goog.asserts.assert(elt, &#39;The DOM element for the tree cannot be null.&#39;);
<a name="line464"></a>  goog.a11y.aria.setRole(elt, &#39;tree&#39;);
<a name="line465"></a>  goog.a11y.aria.setState(elt, &#39;labelledby&#39;, this.getLabelElement().id);
<a name="line466"></a>};
<a name="line467"></a>
<a name="line468"></a>
<a name="line469"></a>/** @override */
<a name="line470"></a>goog.ui.tree.TreeControl.prototype.enterDocument = function() {
<a name="line471"></a>  goog.ui.tree.TreeControl.superClass_.enterDocument.call(this);
<a name="line472"></a>  var el = this.getElement();
<a name="line473"></a>  el.className = this.getConfig().cssRoot;
<a name="line474"></a>  el.setAttribute(&#39;hideFocus&#39;, &#39;true&#39;);
<a name="line475"></a>  this.attachEvents_();
<a name="line476"></a>  this.initAccessibility();
<a name="line477"></a>};
<a name="line478"></a>
<a name="line479"></a>
<a name="line480"></a>/** @override */
<a name="line481"></a>goog.ui.tree.TreeControl.prototype.exitDocument = function() {
<a name="line482"></a>  goog.ui.tree.TreeControl.superClass_.exitDocument.call(this);
<a name="line483"></a>  this.detachEvents_();
<a name="line484"></a>};
<a name="line485"></a>
<a name="line486"></a>
<a name="line487"></a>/**
<a name="line488"></a> * Adds the event listeners to the tree.
<a name="line489"></a> * @private
<a name="line490"></a> */
<a name="line491"></a>goog.ui.tree.TreeControl.prototype.attachEvents_ = function() {
<a name="line492"></a>  var el = this.getElement();
<a name="line493"></a>  el.tabIndex = 0;
<a name="line494"></a>
<a name="line495"></a>  var kh = this.keyHandler_ = new goog.events.KeyHandler(el);
<a name="line496"></a>  var fh = this.focusHandler_ = new goog.events.FocusHandler(el);
<a name="line497"></a>
<a name="line498"></a>  this.getHandler().
<a name="line499"></a>      listen(fh, goog.events.FocusHandler.EventType.FOCUSOUT, this.handleBlur_).
<a name="line500"></a>      listen(fh, goog.events.FocusHandler.EventType.FOCUSIN, this.handleFocus_).
<a name="line501"></a>      listen(kh, goog.events.KeyHandler.EventType.KEY, this.handleKeyEvent).
<a name="line502"></a>      listen(el, goog.events.EventType.MOUSEDOWN, this.handleMouseEvent_).
<a name="line503"></a>      listen(el, goog.events.EventType.CLICK, this.handleMouseEvent_).
<a name="line504"></a>      listen(el, goog.events.EventType.DBLCLICK, this.handleMouseEvent_);
<a name="line505"></a>};
<a name="line506"></a>
<a name="line507"></a>
<a name="line508"></a>/**
<a name="line509"></a> * Removes the event listeners from the tree.
<a name="line510"></a> * @private
<a name="line511"></a> */
<a name="line512"></a>goog.ui.tree.TreeControl.prototype.detachEvents_ = function() {
<a name="line513"></a>  this.keyHandler_.dispose();
<a name="line514"></a>  this.keyHandler_ = null;
<a name="line515"></a>  this.focusHandler_.dispose();
<a name="line516"></a>  this.focusHandler_ = null;
<a name="line517"></a>};
<a name="line518"></a>
<a name="line519"></a>
<a name="line520"></a>/**
<a name="line521"></a> * Handles mouse events.
<a name="line522"></a> * @param {!goog.events.BrowserEvent} e The browser event.
<a name="line523"></a> * @private
<a name="line524"></a> */
<a name="line525"></a>goog.ui.tree.TreeControl.prototype.handleMouseEvent_ = function(e) {
<a name="line526"></a>  this.logger_.fine(&#39;Received event &#39; + e.type);
<a name="line527"></a>  var node = this.getNodeFromEvent_(e);
<a name="line528"></a>  if (node) {
<a name="line529"></a>    switch (e.type) {
<a name="line530"></a>      case goog.events.EventType.MOUSEDOWN:
<a name="line531"></a>        node.onMouseDown(e);
<a name="line532"></a>        break;
<a name="line533"></a>      case goog.events.EventType.CLICK:
<a name="line534"></a>        node.onClick_(e);
<a name="line535"></a>        break;
<a name="line536"></a>      case goog.events.EventType.DBLCLICK:
<a name="line537"></a>        node.onDoubleClick_(e);
<a name="line538"></a>        break;
<a name="line539"></a>    }
<a name="line540"></a>  }
<a name="line541"></a>};
<a name="line542"></a>
<a name="line543"></a>
<a name="line544"></a>/**
<a name="line545"></a> * Handles key down on the tree.
<a name="line546"></a> * @param {!goog.events.BrowserEvent} e The browser event.
<a name="line547"></a> * @return {boolean} The handled value.
<a name="line548"></a> */
<a name="line549"></a>goog.ui.tree.TreeControl.prototype.handleKeyEvent = function(e) {
<a name="line550"></a>  var handled = false;
<a name="line551"></a>
<a name="line552"></a>  // Handle typeahead and navigation keystrokes.
<a name="line553"></a>  handled = this.typeAhead_.handleNavigation(e) ||
<a name="line554"></a>            (this.selectedItem_ &amp;&amp; this.selectedItem_.onKeyDown(e)) ||
<a name="line555"></a>            this.typeAhead_.handleTypeAheadChar(e);
<a name="line556"></a>
<a name="line557"></a>  if (handled) {
<a name="line558"></a>    e.preventDefault();
<a name="line559"></a>  }
<a name="line560"></a>
<a name="line561"></a>  return handled;
<a name="line562"></a>};
<a name="line563"></a>
<a name="line564"></a>
<a name="line565"></a>/**
<a name="line566"></a> * Finds the containing node given an event.
<a name="line567"></a> * @param {!goog.events.BrowserEvent} e The browser event.
<a name="line568"></a> * @return {goog.ui.tree.BaseNode} The containing node or null if no node is
<a name="line569"></a> *     found.
<a name="line570"></a> * @private
<a name="line571"></a> */
<a name="line572"></a>goog.ui.tree.TreeControl.prototype.getNodeFromEvent_ = function(e) {
<a name="line573"></a>  // find the right node
<a name="line574"></a>  var node = null;
<a name="line575"></a>  var target = e.target;
<a name="line576"></a>  while (target != null) {
<a name="line577"></a>    var id = target.id;
<a name="line578"></a>    node = goog.ui.tree.BaseNode.allNodes[id];
<a name="line579"></a>    if (node) {
<a name="line580"></a>      return node;
<a name="line581"></a>    }
<a name="line582"></a>    if (target == this.getElement()) {
<a name="line583"></a>      break;
<a name="line584"></a>    }
<a name="line585"></a>    target = target.parentNode;
<a name="line586"></a>  }
<a name="line587"></a>  return null;
<a name="line588"></a>};
<a name="line589"></a>
<a name="line590"></a>
<a name="line591"></a>/**
<a name="line592"></a> * Creates a new tree node using the same config as the root.
<a name="line593"></a> * @param {string} html The html content of the node label.
<a name="line594"></a> * @return {goog.ui.tree.TreeNode} The new item.
<a name="line595"></a> */
<a name="line596"></a>goog.ui.tree.TreeControl.prototype.createNode = function(html) {
<a name="line597"></a>  // Some projects call createNode without arguments which causes failure.
<a name="line598"></a>  // See http://goto/misuse-createnode
<a name="line599"></a>  // TODO(user): Fix them and remove the html || &#39;&#39; workaround.
<a name="line600"></a>  return new goog.ui.tree.TreeNode(html || &#39;&#39;, this.getConfig(),
<a name="line601"></a>      this.getDomHelper());
<a name="line602"></a>};
<a name="line603"></a>
<a name="line604"></a>
<a name="line605"></a>/**
<a name="line606"></a> * Allows the caller to notify that the given node has been added or just had
<a name="line607"></a> * been updated in the tree.
<a name="line608"></a> * @param {goog.ui.tree.BaseNode} node New node being added or existing node
<a name="line609"></a> *    that just had been updated.
<a name="line610"></a> */
<a name="line611"></a>goog.ui.tree.TreeControl.prototype.setNode = function(node) {
<a name="line612"></a>  this.typeAhead_.setNodeInMap(node);
<a name="line613"></a>};
<a name="line614"></a>
<a name="line615"></a>
<a name="line616"></a>/**
<a name="line617"></a> * Allows the caller to notify that the given node is being removed from the
<a name="line618"></a> * tree.
<a name="line619"></a> * @param {goog.ui.tree.BaseNode} node Node being removed.
<a name="line620"></a> */
<a name="line621"></a>goog.ui.tree.TreeControl.prototype.removeNode = function(node) {
<a name="line622"></a>  this.typeAhead_.removeNodeFromMap(node);
<a name="line623"></a>};
<a name="line624"></a>
<a name="line625"></a>
<a name="line626"></a>/**
<a name="line627"></a> * Clear the typeahead buffer.
<a name="line628"></a> */
<a name="line629"></a>goog.ui.tree.TreeControl.prototype.clearTypeAhead = function() {
<a name="line630"></a>  this.typeAhead_.clear();
<a name="line631"></a>};
<a name="line632"></a>
<a name="line633"></a>
<a name="line634"></a>/**
<a name="line635"></a> * A default configuration for the tree.
<a name="line636"></a> */
<a name="line637"></a>goog.ui.tree.TreeControl.defaultConfig = {
<a name="line638"></a>  indentWidth: 19,
<a name="line639"></a>  cssRoot: goog.getCssName(&#39;goog-tree-root&#39;) + &#39; &#39; +
<a name="line640"></a>      goog.getCssName(&#39;goog-tree-item&#39;),
<a name="line641"></a>  cssHideRoot: goog.getCssName(&#39;goog-tree-hide-root&#39;),
<a name="line642"></a>  cssItem: goog.getCssName(&#39;goog-tree-item&#39;),
<a name="line643"></a>  cssChildren: goog.getCssName(&#39;goog-tree-children&#39;),
<a name="line644"></a>  cssChildrenNoLines: goog.getCssName(&#39;goog-tree-children-nolines&#39;),
<a name="line645"></a>  cssTreeRow: goog.getCssName(&#39;goog-tree-row&#39;),
<a name="line646"></a>  cssItemLabel: goog.getCssName(&#39;goog-tree-item-label&#39;),
<a name="line647"></a>  cssTreeIcon: goog.getCssName(&#39;goog-tree-icon&#39;),
<a name="line648"></a>  cssExpandTreeIcon: goog.getCssName(&#39;goog-tree-expand-icon&#39;),
<a name="line649"></a>  cssExpandTreeIconPlus: goog.getCssName(&#39;goog-tree-expand-icon-plus&#39;),
<a name="line650"></a>  cssExpandTreeIconMinus: goog.getCssName(&#39;goog-tree-expand-icon-minus&#39;),
<a name="line651"></a>  cssExpandTreeIconTPlus: goog.getCssName(&#39;goog-tree-expand-icon-tplus&#39;),
<a name="line652"></a>  cssExpandTreeIconTMinus: goog.getCssName(&#39;goog-tree-expand-icon-tminus&#39;),
<a name="line653"></a>  cssExpandTreeIconLPlus: goog.getCssName(&#39;goog-tree-expand-icon-lplus&#39;),
<a name="line654"></a>  cssExpandTreeIconLMinus: goog.getCssName(&#39;goog-tree-expand-icon-lminus&#39;),
<a name="line655"></a>  cssExpandTreeIconT: goog.getCssName(&#39;goog-tree-expand-icon-t&#39;),
<a name="line656"></a>  cssExpandTreeIconL: goog.getCssName(&#39;goog-tree-expand-icon-l&#39;),
<a name="line657"></a>  cssExpandTreeIconBlank: goog.getCssName(&#39;goog-tree-expand-icon-blank&#39;),
<a name="line658"></a>  cssExpandedFolderIcon: goog.getCssName(&#39;goog-tree-expanded-folder-icon&#39;),
<a name="line659"></a>  cssCollapsedFolderIcon: goog.getCssName(&#39;goog-tree-collapsed-folder-icon&#39;),
<a name="line660"></a>  cssFileIcon: goog.getCssName(&#39;goog-tree-file-icon&#39;),
<a name="line661"></a>  cssExpandedRootIcon: goog.getCssName(&#39;goog-tree-expanded-folder-icon&#39;),
<a name="line662"></a>  cssCollapsedRootIcon: goog.getCssName(&#39;goog-tree-collapsed-folder-icon&#39;),
<a name="line663"></a>  cssSelectedRow: goog.getCssName(&#39;selected&#39;)
<a name="line664"></a>};
</pre>


</body>
</html>
